package com.wu.service.weixin.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wu.common.constant.Constant;
import com.wu.common.page.PageResult;
import com.wu.common.service.impl.BaseServiceImpl;
import com.wu.dao.weixin.dao.WeixinClanMapper;
import com.wu.dao.weixin.vo.WeixinClanVO;
import com.wu.entity.weixin.po.WeixinClan;
import com.wu.service.sys.query.SysUserQuery;
import com.wu.service.sys.query.WeixinClanQuery;
import com.wu.service.weixin.service.WxClanService;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户管理
 *
 * @author wzd
 */
@Service
@AllArgsConstructor
public class WxClanServiceImpl extends BaseServiceImpl<WeixinClanMapper, WeixinClan> implements WxClanService {

    @Override
    public PageResult<WeixinClanVO> page(WeixinClanQuery query) {
        // 查询参数
        Map<String, Object> params = getParams(query);
        // 分页查询
        IPage<WeixinClan> page = getPage(query);
        params.put(Constant.PAGE, page);
        // 数据列表
        List<WeixinClanVO> list = baseMapper.getList(params);
        return new PageResult<WeixinClanVO>(list, page.getTotal());
    }

    @Override
    public void deleteByIds(List<String> idList) {
        baseMapper.deleteByIds(idList);
    }

    @Override
    public void save(WeixinClanVO vo) {
        WeixinClan entity  = new WeixinClan();
        BeanUtils.copyProperties(vo,entity);
        baseMapper.insert(entity);
    }


    private Map<String, Object> getParams(WeixinClanQuery query){
        Map<String, Object> params = new HashMap<>();
        params.put("clanName", query.getClanName());

        // 数据权限
        params.put(Constant.DATA_SCOPE, getDataScope("t1", null));

        return params;
    }

}
